package cn.dgut.training.utils;

import cn.dgut.training.exception.UnLoginException;

public class UserTokenUtil {


	public static String generateToken(Long id) {
        JwtHelperUtil jwtHelper = new JwtHelperUtil();
        return jwtHelper.createToken(id);
    }


    public static Long getUserId(String token) {
        JwtHelperUtil jwtHelper = new JwtHelperUtil();
    	Long userId = jwtHelper.verifyTokenAndGetUserId(token).longValue();
    	if(userId == null || userId .equals(0L)){
    	    throw new UnLoginException();
    	}
        return userId;
    }
}
